{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# EntityStrings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>YiJingFramework.EntityRelations, 4.0.1</span></li></ul></div></div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#r \"nuget:YiJingFramework.EntityRelations\"\n",
    "using YiJingFramework.EntityRelations.EntityStrings;\n",
    "using YiJingFramework.EntityRelations.EntityStrings.Conversions;\n",
    "using YiJingFramework.EntityRelations.EntityStrings.Extensions;\n",
    "using YiJingFramework.EntityRelations.WuxingRelations;\n",
    "using YiJingFramework.PrimitiveTypes;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`YiJingFramework.EntityRelations.EntityStrings` 命名空间主要提供易学实体到字符串的转换。举例而言："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "癸卯兔年\n",
      "生我为父母\n"
     ]
    }
   ],
   "source": [
    "var toShengxiao = DizhiToStringConversions.Shengxiao;\n",
    "Tiangan yearGan = Tiangan.Gui;\n",
    "Dizhi yearZhi = Dizhi.Mao;\n",
    "var s = $\"{yearGan:C}{yearZhi:C}{yearZhi.ToString(toShengxiao)}年\";\n",
    "Console.WriteLine(s);\n",
    "\n",
    "var toChinese = WuxingRelationToStringConversions.InChinese;\n",
    "var toLiuqin = WuxingRelationToStringConversions.Liuqin;\n",
    "WuxingRelation relation = WuxingRelation.ShengsMe;\n",
    "s = $\"{relation.ToString(toChinese)}为{relation.ToString(toLiuqin)}\";\n",
    "Console.WriteLine(s);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "实际上，直接调用 `toShengxiao(yearZhi)` 也有一样的效果，只是写成 `ToString` 的形式更加好看一些。此外，也支持自己定义转换："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "String[Hello World]\n",
      "Int32[23]\n"
     ]
    }
   ],
   "source": [
    "EntityToStringConversion<object> myConversation = (object x) => $\"{x.GetType().Name}[{x}]\";\n",
    "Console.WriteLine(\"Hello World\".ToString(myConversation));\n",
    "Console.WriteLine(23.ToString(myConversation));"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".NET (C#)",
   "language": "C#",
   "name": ".net-csharp"
  },
  "language_info": {
   "file_extension": ".cs",
   "mimetype": "text/x-csharp",
   "name": "C#",
   "pygments_lexer": "csharp",
   "version": "3.12.2"
  },
  "polyglot_notebook": {
   "kernelInfo": {
    "defaultKernelName": "csharp",
    "items": [
     {
      "aliases": [],
      "name": "csharp"
     }
    ]
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
